#include <d3d9.h>
#include <d3dx9.h>
#include <vector>
#include "Game.h"
#include "Textures.h"

// A vector containing references to the textures.
std::vector<LPDIRECT3DTEXTURE9>* Minicraft::Textures::TextureRefs;

// Loads all the textures for the game.
void Minicraft::Textures::LoadTextures()
{
	Minicraft::Textures::TextureRefs = new std::vector<LPDIRECT3DTEXTURE9>();

	// grass
	Minicraft::Textures::LoadTexture(".\\Textures\\grass.png");

	// grass_side
	Minicraft::Textures::LoadTexture(".\\Textures\\grass_side.png");

	// dirt
	Minicraft::Textures::LoadTexture(".\\Textures\\dirt.png");
}

// Returns a pointer to a texture based on the value of the passed Texture enum.
LPDIRECT3DTEXTURE9 Minicraft::Textures::GetTextureByEnum(Minicraft::Textures::TextureList::e texture)
{
	return Minicraft::Textures::TextureRefs->at(texture);
}

// Loads a single texture.
void Minicraft::Textures::LoadTexture(LPCSTR textureFilename)
{
	LPDIRECT3DTEXTURE9 textureToLoad = NULL;
	D3DXCreateTextureFromFile(Minicraft::BufferCollectionInstance->GetD3DDevice(), textureFilename, &textureToLoad);

	Minicraft::Textures::TextureRefs->push_back(textureToLoad);
}

// Unloads all the textures for the game.
void Minicraft::Textures::UnloadTextures()
{
	while (Minicraft::Textures::TextureRefs->size() > 0)
	{
		Minicraft::Textures::TextureRefs->at( Minicraft::Textures::TextureRefs->size() - 1 )->Release();
		Minicraft::Textures::TextureRefs->pop_back();
	}
}